package cn.reyuxi.emptyview

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.viewpager2.widget.ViewPager2

class MainActivity : AppCompatActivity() {

    private val pageAdapter: MainPagerAdapter by lazy {
        MainPagerAdapter()
    }

    private lateinit var viewpager: ViewPager2

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        findViewById<Button>(R.id.btn_hide).setOnClickListener {
            pageAdapter.hideEmpty(viewpager.currentItem)
        }

        findViewById<Button>(R.id.btn_show_loading).setOnClickListener {
            pageAdapter.showEmpty(viewpager.currentItem, EmptyViewType.LOADING)
        }

        findViewById<Button>(R.id.btn_show_no_data).setOnClickListener {
            pageAdapter.showEmpty(viewpager.currentItem, EmptyViewType.NO_DATA)
        }

        viewpager = findViewById<ViewPager2>(R.id.pager).also {
            it.adapter = pageAdapter
        }
    }
}